/*************************************************************************
	> File Name: RandomAccessFileTest.java
	> Author: Potter
	> Mail: tobewhatwewant@gmail.com 
	> Created Time: 2014年06月02日 星期一 00时26分47秒
 ************************************************************************/
import java.io.RandomAccessFile;

public class RandomAccessFileTest {
    public static void main(String[] args) throws Exception{
        write();
        read();
    }

    static void write() {
        try {
            RandomAccessFile raf = new RandomAccessFile("tmp.txt", "rw");
            raf.writeInt(10);
            raf.writeBoolean(true);
            raf.writeChar('a');
            raf.writeUTF("hello");
            // raf.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static void read() throws Exception {
        //try {
            RandomAccessFile raf = new RandomAccessFile("tmp.txt", "rw");
            System.out.println(raf.readInt());
            System.out.println(raf.readBoolean());
            raf.skipBytes(2);
            System.out.println(raf.readUTF());
        //} catch (Exception e) {
        //    e.printStackTrace();
        //}
    }
}
